package com.szlanyou.protocol_base;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author 陈章
 * create at 2021/1/19 17:37
 * desc:协议帧解析
 */
public abstract class BaseProtocolHandler {
    protected OnDecodeListener onDecodeListener;
    public void setOnDecodeListener(OnDecodeListener onDecodeListener) {
        this.onDecodeListener = onDecodeListener;
    }

    /**
     * 读数据流
     * @param in
     * @throws IOException
     */
    public abstract  void handle(InputStream in);

    /**
     * 直接处理数据
     * @param in
     */
    public abstract  void handle(byte[] in);

    public interface OnDecodeListener{
        /**
         * 解析出一帧数据
         * @param oneFrameData
         */
        void onDecoded(String oneFrameData);

        /**
         * 读取异常
         * @param e
         */
        void onReadException(Throwable e);
    }
}
